#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QRegExpValidator>
#include <QString>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->lineEdit->setPlaceholderText("请输入姓名");
    ui->lineEdit->setClearButtonEnabled(1);

    ui->lineEdit_2->setPlaceholderText("请输入密码");
    ui->lineEdit_2->setClearButtonEnabled(1);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);

    ui->lineEdit_3->setPlaceholderText("请输入电话");
    ui->lineEdit_3->setClearButtonEnabled(1);
    //电话是有格式的，一般都是13位数字，用inputMask来设置格式
    //ui->lineEdit_3->setInputMask("000-0000-0000");

    ui->pushButton->setEnabled(0);

    QRegExp regexp("^1\\d{10}$");
    ui->lineEdit_3->setValidator(new QRegExpValidator(regexp));

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString gender = ui->radioButton->isChecked() ? "男" :"女";
    qDebug()<<"姓名"<<ui->lineEdit->text()
            <<"密码"<<ui->lineEdit_2->text()
            <<"性别"<<gender
            <<"电话"<<ui->lineEdit_3->text();
}

void Widget::on_lineEdit_3_textEdited(const QString &arg1)
{
    QString text = arg1;
    int pos = 0;

    if(ui->lineEdit_3->validator()->validate(text,pos) == QValidator::Acceptable)
        //验证通过
        ui->pushButton->setEnabled(1);
    else
       ui->pushButton->setEnabled(0);
}
